< previous page page_389 next page >

Page 389
The following section introduces homogeneous coordinates that allow you to manipulate all of these transformations with matrices. The sections after that explain how you can combine simple transformation matrices to create more complicated transformations.
Homogeneous Coordinates
To represent a two-dimensional point in homogeneous coordinates, you store the point as a vector [S * x, S * y, S]. Here x and y are the point's normal X and Y coordinates, and S is a scale factor. For example, the point (10, 4) might be stored as [20, 8, 2] or as [5, 2, 0.5]. Both of these vectors represent the same point (10, 4). In the first case, the value of S is 2. In the second, S is 0.5.
Usually, for convenience, the components in a vector are normalized by dividing them by the scale factor S. This makes the new scale factor 1 and the other components the same as their normal X and Y coordinates. The normalized representation of the point (10, 4) is [10, 4, 1].
When you represent points as vectors, you can represent translation, scaling, and rotation as matrices. To apply a transformation matrix to a point, you multiply the point's vector by the transformation matrix. The result is a new vector that gives the point's transformed coordinates.
Before specific transformation matrices are described, the following two sections review matrix/vector and matrix/matrix multiplication. If you are comfortable with these operations, you can safely skip these sections.
Vector/Matrix Multiplication
When you multiply a vector by a matrix, the result is a new vector. To find the value of the ith component in the result, multiply the components in the vector by the corresponding entries in the ith column of the matrix and add them together. This makes more sense after you have worked through a few examples.
Suppose you want to multiply the vector [a, b, c] with the matrix:
e10a6a0a59f035e870d90cca05b85fce.gif
 z0409-01.gif
The first component of the result is given by the sum of the products of [a, b, c] with the entries in the first column of the matrix. This value is a * m11 + b * m21 + c * m31. In a similar way, you can compute the values for the second and third components in the new vector.
You can use the following Visual Basic code to multiply a vector and a matrix. Here V is an array holding the vector, M is a two-dimensional array holding the matrix, and Result is the array that should hold the resulting vector.
e10a6a0a59f035e870d90cca05b85fce.gif
For i = 1 To 3

 
< previous page page_389 next page >